<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core" 
	xmlns:ui="http://java.sun.com/jsf/facelets">

<ui:composition template="/template/layout.xhtml">
	<ui:define name="conteudo">
		<script>
			// When the page is ready
			$(document).ready(function(){
				$("#opener").click(function(){
					$("#teste").toggle(); return false;
				});		   		
			});
		 </script>

		<br />
		<br />
		<div id="path">
			<h1>
				<h:outputText value="#{forumBean.topico.titulo}" />
			</h1>
			<hr />
			<br />
			<h:outputLink id="opener">
				Nova Resposta
			</h:outputLink>
			<div id="teste" style="display: none;">
				<h:form><br/><br/><br/>
				<fieldset>
					<legend>Dados</legend>
					<br /><br/>
					<h:panelGrid columns="3">						
						<h:outputLabel value="Mensagem:" for="mensagem" styleClass="label"/>
						<h:inputTextarea id="mensagem" class="rotulos" size="40" value="#{forumBean.mensagem.mensagem}" required="true" requiredMessage="* O campo [Mensagem] é obrigatório!"/>
						<h:message for="mensagem" showSummary="true" showDetail="false" class="error"/>
				    </h:panelGrid>
				    
		    		<br /><br/>
		            <h:commandButton class="botaosalvar" value="Salvar" image="../resources/imagens/botoes/botao-salvar.png" action="#{forumBean.cadastrarResposta}" >
		            	<f:setPropertyActionListener target="#{forumBean.mensagem.usuario}" value="#{loginBean.usuario}" />
		            	<f:setPropertyActionListener target="#{forumBean.mensagem.topico}" value="#{forumBean.topico}" />            	
		            </h:commandButton>	      		
				</fieldset>
				</h:form>
			</div>
		</div>
		<h:form>
			<br />
			<br />
			<br />
			<p:dataTable id="basic" var="mensagem"
				value="#{forumBean.topico.mensagens}">
				<p:column>
					<f:facet name="header">  
						Autor  
			        </f:facet>
					<h:outputText value="#{mensagem.usuario.nome}" />
				</p:column>
				<p:column>
					<f:facet name="header">  
			            Mensagem  
			        </f:facet>
					<h:outputText value="#{mensagem.dataHora}" />
					<br />
					<h:outputText value="#{mensagem.mensagem}" />
				</p:column>
				<p:column>
					<f:facet name="header">
						Ação
					</f:facet>					
		            <h:commandLink rendered="#{loginBean.usuario.user.equals(mensagem.usuario.user)}" value="delete" action="#{forumBean.apagarMensagem}">
		            	<f:setPropertyActionListener target="#{forumBean.mensagem}" value="#{mensagem}" />				            	
		            </h:commandLink>
				</p:column>
			</p:dataTable>
		</h:form>
	</ui:define>
</ui:composition>
</html>